'use strict';

/* Controllers */
app.controller('landlordListCtl', function($scope, $http, rest, $compile, $location, ngDialog, user, tipService, $state, $window, uiLoad, $rootScope, $ocLazyLoad, $timeout) {

    var token = $window.localStorage.getItem("token");
    var id = $window.localStorage.getItem("id");

    //方法级权限
    var accessStr = $window.localStorage.getItem("accessStr");
    $scope.btns = {
            add: 'innjia', //新建
            delete: 'innjia', //删除
            edit: 'innjia', //编辑
            jurisdiction: 'innjia', //权限分配
            resetPasswords: 'innjia', //重置密码
            addmember: 'innjia', //添加成员
            exportExcel: 'innjia', //导出表格
            batchExportImg: 'innjia', //批量导出图片
            details: 'innjia', //详情
            rent: 'innjia', //租赁PDF
            list: 'innjia', //列表
            batchApproval: 'innjia', //批量审批
            batchClaim: 'innjia' //批量认领
        }
        //延迟执行 - 当左侧菜单生产完毕再获取当前菜单的ID 利用ui-sref-active有且只有一个active即当前的特性用jq去获取预先存储在菜单上的id
    user.response().then(function(res) {
        var nowId = $(document).find(".navItem.active").attr("data-id");
        rest.decoJava({
            type: "post",
            url: "/tenancy-sys/admin/menu/detail/" + nowId,
            data: "",
            //contentType:"application/json",
            beforeSend: function(request) {
                request.setRequestHeader("token", token);
            },
            success: function(data) {
                console.log(data)
                if (data.code == "0000") {
                    //匹配权限
                    angular.forEach(data.result.menuMethods, function(data) {
                        if (data.methodTagName == "add") {
                            $scope.btns.add = data.id;
                        } else if (data.methodTagName == "delete") {
                            $scope.btns.delete = data.id;
                        } else if (data.methodTagName == "edit") {
                            $scope.btns.edit = data.id;
                        } else if (data.methodTagName == "jurisdiction") {
                            $scope.btns.jurisdiction = data.id;
                        } else if (data.methodTagName == "resetPasswords") {
                            $scope.btns.resetPasswords = data.id;
                        } else if (data.methodTagName == "addmember") {
                            $scope.btns.addmember = data.id;
                        } else if (data.methodTagName == "exportExcel") {
                            $scope.btns.exportExcel = data.id;
                        } else if (data.methodTagName == "batchExportImg") {
                            $scope.btns.batchExportImg = data.id;
                        } else if (data.methodTagName == "details") {
                            $scope.btns.details = data.id;
                        } else if (data.methodTagName == "rent") {
                            $scope.btns.rent = data.id;
                        } else if (data.methodTagName == "list") {
                            $scope.btns.list = data.id;
                        } else if (data.methodTagName == "batchApproval") {
                            $scope.btns.batchApproval = data.id;
                        } else if (data.methodTagName == "batchClaim") {
                            $scope.btns.batchClaim = data.id;
                        }
                    })
                } else if (data.message == "菜单Id有误！！！") {
                    // $window.location.reload();
                } else {
                    layer.msg(data.message + '请刷新试试', {
                        offset: 't',
                        icon: 2
                    });
                }
            }
        });

    })

    $scope.queryParams = {
        orderFlag: 0
    };
    $scope.checkStatus = {};
    $scope.landlordType = {};
    $scope.checkTypeArray = [{
        "name": "全部",
        "value": ""
    }, {
        "name": "回退补件",
        "value": "RETURNBACK"
    }, {
        "name": "审核通过",
        "value": "CHECKSUCCESS"
    }, {
        "name": "审核中",
        "value": "INREVIEW"
    }, {
        "name": "审核未通过",
        "value": "CHECKFAILE"
    }, {
        "name": "房东待审核",
        "value": "UNCHECK"
    }];

    $scope.owenrTypeArray = [{
        "name": "全部",
        "value": ""
    }, 
    // {
    //     "name": "职业房东（个人）",
    //     "value": "PERSON"
    // }, 
    {
        "name": "职业房东（企业）",
        "value": "ENTERPRISE"
    }, {
        "name": "业主（产权拥有）",
        "value": "OWNER"
    }];
    var tmpHouseIdArr = "";
	var tabHeight = ($window.innerHeight - 420) + "px"; //table内容区高度
    initDataTables();
    function initDataTables() {
        $scope.dataTablelandlordManageSettings = {
            "sAjaxSource": "/tenancy-sys/landlord/queryLandlordList",
            "sScrollY": tabHeight, //给定高度，内容超出即出滚动条
	        "bScrollCollapse": false, //不管内容多少高度固定
	        "aLengthMenu": [25, 50, 100, 200],
	        "iDisplayLength": 25,
	        "sDom": '<"top">rt<"bottom"lip><"clear">', //位置 l-每页显示数量,f-过滤输入,t-表单Table,i-信息,p-翻页
	        "bAutoWidth": true,  //自适应列宽
            "aoColumns": [{
                    "mDataProp": "",
                    "sDefaultContent": "",
                    "sClass": "center handle-ck"
                }, {
                    "mDataProp": "createTime",
                    "sTitle": "申请时间",
                    "sDefaultContent": "",
                    "sClass": "center"
                }, {
                    "mDataProp": "name",
                    "sTitle": "房东姓名",
                    "sDefaultContent": "",
                    "sClass": "center"
                }, {
                    "mDataProp": "company",
                    "sTitle": "企业名称",
                    "sDefaultContent": "",
                    "sClass": "center"
                }, {
                    "mDataProp": "mobile",
                    "sTitle": "房东手机号",
                    "sDefaultContent": "",
                    "sClass": "center"
                }, {
                    "mDataProp": "landlordType",
                    "sTitle": "房东性质",
                    "sDefaultContent": "",
                    "sClass": "center landlordType"
                },


                {
                    "mDataProp": "checkStatus",
                    "sTitle": "审核状态",
                    "sDefaultContent": "",
                    "sClass": "center landlordStatus"
                }, {
                    "mDataProp": "updateTime",
                    "sTitle": "准入时间",
                    "sDefaultContent": "",
                    "sClass": "center"
                }, {
                    "mDataProp": "creditLine",
                    "sTitle": "总授信额度(元)",
                    "sDefaultContent": "",
                    "sClass": "center"
                }, {
                    "mDataProp": "receivedAmount",
                    "sTitle": "已用额度(元)",
                    "sDefaultContent": "",
                    "sClass": "center"
                }, {
                    "mDataProp": "applySumAmount",
                    "sTitle": "在途申请额度(元)",
                    "sDefaultContent": "",
                    "sClass": "center"
                }, {
                    "mDataProp": "availableCreditLine",
                    "sTitle": "可用额度(元)",
                    "sDefaultContent": "",
                    "sClass": "center"
                },

                {
                    "mDataProp": "operate",
                    "sTitle": "操作",
                    "sDefaultContent": "",
                    "sClass": "center handle-td operation"
                }
            ],
            "fnRowCallback": function(nRow, aData, iDisplayIndex) {
                var btnStr = "";
                // 指派  <dd><a href='javascript:' ng-click='assignTo(\"" + aData.id + "\")'>指派</a></dd>\
                if (aData.checkStatus == "CHECKSUCCESS") {
                    btnStr += " <a class='operation-btn'>\
                                <img src='img/operation.png' width='20px' height='20px' />\
                                <div class='operation-none' >\
                                    <dl class='operation oper-triangle'>\
                                        <dd><a href='javascript:' data-btn='btns.details' ng-click='viewLandDetails(\"" + aData.id + "\",\"" + aData.landlordType + "\")'>房东详情</a></dd>\
                                        <dd><a href='javascript:' data-btn='btns.list' ng-click='viewLandList(\"" + aData.id + "\")'>房源列表</a></dd>\
                                        <span class='z'>◆</span><span class='y'>◆</span>\
                                    </dl>\
                                </div>\
                            </a>";

                } else {
                    btnStr += " <a class='operation-btn'>\
                                <img src='img/operation.png' width='20px' height='20px' />\
                                <div class='operation-none' >\
                                    <dl class='operation oper-triangle'>\
                                        <dd><a href='javascript:' data-btn='btns.details' ng-click='viewLandDetails(\"" + aData.id + "\",\"" + aData.landlordType + "\")'>房东详情</a></dd>\
                                        <span class='z'>◆</span><span class='y'>◆</span>\
                                    </dl>\
                                </div>\
                            </a>";

                }


                //btnStr += "<a href='javascript:;' class='btn btn-yellow' style='margin-right:10px;' ng-click='viewHouseDetails(\"" + aData.houseId + "\",$event)'>查看详情</a>";

                $(nRow).find(".handle-td").append($compile(btnStr)($scope));

                // var checkStr = "";
                // checkStr += '<input type="checkbox" data-index="' + iDisplayIndex + '" value="' + $scope.myDatas.result.list[iDisplayIndex].id + '" class="checkchild" />';
                // $(nRow).find(".handle-ck").append($compile(checkStr)($scope));

                $(nRow).find(".operation-btn").on('click', function() {
                    var sopt = $(this).parent().find(".operation-none");
                    if (sopt.css('display') == 'none') {
                        sopt.show();
                        $scope.isCoverBgShow = true;
                        $scope.$apply();
                    } else {
                        sopt.hide();
                        $scope.isCoverBgShow = false;
                        $scope.$apply();
                    }
                });

                var checkStr = "";
                checkStr += '<input type="checkbox" data-index="' + iDisplayIndex + '" value="' + $scope.myDatas.result[iDisplayIndex].id + '" class="checkchild" />';
                $(nRow).find(".handle-ck").append($compile(checkStr)($scope));

                if (aData.checkStatus == "RETURNBACK") {
                    var statusStr = "回退补件";
                } else if (aData.checkStatus == "CHECKSUCCESS") {
                    var statusStr = "审核通过";
                } else if (aData.checkStatus == "INREVIEW") {
                    var statusStr = "审核中";
                } else if (aData.checkStatus == "CHECKFAILE") {
                    var statusStr = "审核未通过";
                } else {
                    var statusStr = "房东待审核";
                }

                $(nRow).find(".landlordStatus").empty().append(statusStr);

                if (aData.landlordType == "PERSON") {
                    var statusStr = "职业房东（个人）";
                } else if (aData.landlordType == "ENTERPRISE") {
                    var statusStr = "职业房东（企业）";
                } else {
                    var statusStr = "业主（产权拥有）";
                }


                $(nRow).find(".landlordType").empty().append(statusStr);


                tmpHouseIdArr += aData.houseId + ",";
                if (iDisplayIndex >= 9) {
                    // console.log(tmpHouseIdArr);
                }
            },
            "fnDrawCallback": function(oSettings) {
                $scope.checkStatusValue = $scope.queryParams.checkStatus;
                if ("number" == typeof $scope.checkStatusValue) {
                    $scope.checkTypeArray.map(function(ele, index) {
                        if ($scope.checkStatusValue == ele.value) {
                            $scope.checkStatus.selected = ele;
                        }
                    })
                }
                $scope.landlordTypeValue = $scope.queryParams.landlordType;
                if ("number" == typeof $scope.landlordTypeValue) {
                    $scope.owenrTypeArray.map(function(ele, index) {
                        if ($scope.landlordTypeValue == ele.value) {
                            $scope.landlordType.selected = ele;
                        }
                    })
                }

            },
            "fnServerParams": function(aoData) {


                if ($scope.checkStatus && $scope.checkStatus.selected) {
                    $scope.queryParams.checkStatus = $scope.checkStatus.selected.value
                }
                if ($scope.landlordType && $scope.landlordType.selected) {
                    $scope.queryParams.landlordType = $scope.landlordType.selected.value
                }
                aoData.push({
                    'name': 'queryParams',
                    'value': $scope.queryParams
                });

                return aoData;
            },
            "fnServerData": function(sSource, aData, fnCallback, dataTableObject) {
                //自定义给datatables传递的参数
                var obj = dataTableObject.oAjaxData,
                    _baseParams = {
                        'page': obj.iDisplayStart / obj.iDisplayLength + 1,
                        'rows': obj.iDisplayLength,
                        // pointPerson:id,

                        'search': 'false',
                        'nd': '1494221804416',
                    };

                var __data = angular.extend({}, _baseParams, obj.queryParams);
                rest.decoJava({
                    type: "post",
                    url: sSource,
                    data: __data,
                    beforeSend: function(request) {
                        request.setRequestHeader("token", token);
                    },
                    success: function(data) {
                        $scope.myDatas = data;
                        var data1 = {
                            'aaData': data.result,
                            'sEcho': obj.sEcho,
                            'iTotalDisplayRecords': data.pager.recordCount,
                            'iTotalRecords': data.records,
                        };
                        fnCallback(data1);
//                      $(dataTableObject.nScrollBody).css('overflow', 'visible');
//                      $(dataTableObject.nScrollBody).css('margin-bottom', 60 + 'px');
                      	$(".dataTables_scroll").css("overflow", "auto");
        				$(".dataTables_scrollBody").css("overflow", "visible");
        				$(".dataTables_scrollBody table").css("marginBottom", "80px");
                    }
                });

                //搜索 说明 只要是点击的搜索就让page为1 并且刷新datatables目的是回到第一页
                //说明 自定义搜索只需在点击搜索的时候改变下datatables传过去的参数 然后$scope.dataTable.fnClearTable()即可
                $scope.search = function() {
                    __data.page = 1;
                    $scope.tablelandlordManageChanged.fnClearTable();
                }

            }
        }
    }


    //正序反序排列
    $('#orderFlags').click(function(event) {
        if ($scope.queryParams.orderFlag == 0) {
            $scope.queryParams.orderFlag = 1;
            $('#triangle').removeClass('triangle-down');
            $('#triangle').addClass('triangle-up');
        } else if ($scope.queryParams.orderFlag == 1) {
            $scope.queryParams.orderFlag = 0;
            $('#triangle').addClass('triangle-down');
            $('#triangle').removeClass('triangle-up');
        }
        console.log($scope.queryParams.orderFlag);
        $scope.tablelandlordManageChanged.fnClearTable();
    });

    $scope.initFinishlandlordManage = function(dataTable) {
        $scope.tablelandlordManageChanged = dataTable;
    }

    //监听房东姓名
    $scope.$watch('_landlordName', function(newValue, oldValue) {
            $scope.queryParams.name = newValue;
        })
        //房东手机号
    $scope.$watch('_landlordPhone', function(newValue, oldValue) {
        $scope.queryParams.mobile = newValue;
    })

    //监听企业名称
    $scope.$watch('_landlorCompany', function(newValue, oldValue) {
        $scope.queryParams.company = newValue;
    })

    //监听小区名称
    $scope.$watch('_areaName', function(newValue, oldValue) {
        $scope.queryParams.areaName = newValue;
    })

    //监听详细地址
    $scope.$watch('_address', function(newValue, oldValue) {
        $scope.queryParams.address = newValue;
    })


    //全部选中和取消
    $scope.allMenu = function(e) {
        var This = angular.element(e.target);
        if (This.is(":checked")) {
            angular.element(".checkchild").prop("checked", true);
        } else {
            angular.element(".checkchild").prop("checked", false);
        }
    }



    $scope.queryUser = function() {
        if ($scope.queryParams.checkStatus && $scope.queryParams.checkStatus.selected) {
            var checkStatusCache = $scope.queryParams.checkStatus.selected;
            if ($scope.queryParams.checkStatus.selected) {
                $scope.queryParams.checkStatus = $scope.queryParams.checkStatus.selected.value
            }
            $scope.tablelandlordManageChanged.fnClearTable();
            $scope.queryParams.checkStatus = {};
            $scope.queryParams.checkStatus.selected = {};
            $scope.queryParams.checkStatus.selected = checkStatusCache;
        } else if ($scope.queryParams.landlordType && $scope.queryParams.landlordType.selected) {
            var landlordTypeCache = $scope.queryParams.landlordType.selected;
            if ($scope.queryParams.landlordType.selected) {
                $scope.queryParams.landlordType = $scope.queryParams.landlordType.selected.value
            }
            $scope.tablelandlordManageChanged.fnClearTable();
            $scope.queryParams.landlordType = {};
            $scope.queryParams.landlordType.selected = {};
            $scope.queryParams.landlordType.selected = landlordTypeCache;
        } else {
            $scope.tablelandlordManageChanged.fnClearTable();
        }

    };

    $scope.resetUser = function() {
        $scope._landlordName = "";
        $scope._landlordPhone = "";
        $scope._landlorCompany = "";

        $scope.checkStatus.selected = undefined;
        $scope.landlordType.selected = undefined;
        

        $('.searchCreateTime').val('');
        // $scope.checkStatus.selected = $scope.checkTypeArray[0];
        // $scope.landlordType.selected = $scope.owenrTypeArray[0];
        $scope.applyDateStart = "";
        $scope.applyDateEnd = "";
        $scope.dateStart = "";
        $scope.dateEnd = "";
        $scope.queryParams = {};
        $scope.tablelandlordManageChanged.fnClearTable();
    }

    $scope.viewLandDetails = function(id, landlordType) {
        //权限控制
        var nowId = this.btns.details;
        if (accessStr.indexOf(nowId) == -1) {
            layer.msg("你没有该操作权限", {
                offset: 't',
                icon: 2
            });
            return false;
        }
        $window.localStorage.setItem('landlordId', id);
        if (landlordType == 'ENTERPRISE') {
            $state.go('app.landlord.landlordJobDetails', {
                landlordId: id
            });

        } else if (landlordType == 'PERSON') {
            $state.go('app.landlord.landlordJobDetails', {
                landlordId: id
            });

        } else {
            $state.go('app.landlord.landlordDetails', {
                landlordId: id
            });
        }

    }

    // 房东房源列表
    $scope.viewLandList = function(id) {
        //权限控制
        var nowId = this.btns.list;
        if (accessStr.indexOf(nowId) == -1) {
            layer.msg("你没有该操作权限", {
                offset: 't',
                icon: 2
            });
            return false;
        }
        // $window.localStorage.setItem("pointPerson",pointPerson);
        $window.localStorage.setItem('landlordId1', id);
        // $state.go('app.landlord.landlordList', {
        //     landlordId: id,
        //     // pointPerson: pointPerson
        // });

        rest.decoJava({
            type: "post",
            url: "/tenancy-sys/admin/house/index",
            data: {
                page: 1,
                rows: 10,
                nd: '1494221804416',
                pageType: 'GeneralManagement',
                landlordId: id
            },
            beforeSend: function(request) {
                request.setRequestHeader("token", token);
            },
            success: function(data) {
                if (data.code == "0000") {
                    if (data.result.models.length != 0) {
                        $state.go('app.house.houseManageList', {
                            landlordId1: id,
                            // pointPerson: pointPerson
                        });
                    } else {
                        tipService.show("body", {
                            message: "该房东还未提交房源",
                            notice: "danger"
                        }, 3);
                        return;
                    }
                }
            }
        });



    }


    $scope.assignTo = function(id) {
        ngDialog.openConfirm({
            template: 'js/module/fund/assignToLand.html',
            resolve: {
                load: function() {
                    return uiLoad.load(['js/module/fund/assignToLand.js'])
                }
            },
            data: {
                landlordId: id
            },
            scope: $scope,
            width: 600,
            // height: 700
        }).then(function(data) {
            $scope.coverBgHide();
        }, function(reason) {
            $scope.coverBgHide();
        });
    }

    //导出excel
    $scope.exportExcel = function() {
        var nowId = this.btns.exportExcel;
        if (accessStr.indexOf(nowId) == -1) {
            layer.msg("你没有该操作权限", {
                offset: 't',
                icon: 2
            });
            return false;
        }
        if ($(".checkchild:checked").length == 0) {
            layer.msg("没有选中项", {
                offset: 't',
                icon: 2,
                time: 0, //不自动关闭
                btn: ['确定'],
                yes: function(index) {
                    layer.close(index);
                }
            });
        } else {

            //选中的数据id
            var idArr = [];
            $(".checkchild").each(function() {
                if ($(this).is(":checked")) {
                    idArr.push($(this).val());
                }
            });
            var _idstring = "";
            angular.forEach(idArr, function(data) {
                _idstring += data + ',';
            })
            var _idstring = _idstring.substring(0, _idstring.length - 1);

            ngDialog.openConfirm({
                template: 'js/module/fund/landlordListExcel.html',
                resolve: {
                    load: function() {
                        return $ocLazyLoad.load('angularFileUpload').then(
                            function() {
                                return uiLoad.load(['js/module/fund/landlordListExcel.js'])
                            });
                    }
                },
                data: {
                    _idstring: _idstring
                },
                scope: $scope,
                width: 1200,
                // height: 700
            }).then(function(data) {
                $scope.tablelandlordManageChanged.fnClearTable();
            }, function(reason) {
                $scope.tablelandlordManageChanged.fnClearTable();
            });
        }
    }


    //导出Img
    $scope.exportImg = function() {
        // $window.localStorage.setItem('landlordIds', id);
        //权限控制
        var nowId = this.btns.batchExportImg;
        if (accessStr.indexOf(nowId) == -1) {
            layer.msg("你没有该操作权限", {
                offset: 't',
                icon: 2
            });
            return false;
        }
        if ($(".checkchild:checked").length == 0) {
            layer.msg("没有选中项", {
                offset: 't',
                icon: 2,
                time: 0, //不自动关闭
                btn: ['确定'],
                yes: function(index) {
                    layer.close(index);
                }
            });
        } else {

            //选中的数据id
            var idArr = [];
            $(".checkchild").each(function() {
                if ($(this).is(":checked")) {
                    idArr.push($(this).val());
                }
            });
            var _idstring = "";
            angular.forEach(idArr, function(data) {
                _idstring += data + ',';
            })
            var _idstring = _idstring.substring(0, _idstring.length - 1);

            ngDialog.openConfirm({
                template: 'js/module/fund/landlordExportImg.html',
                resolve: {
                    load: function() {
                        return $ocLazyLoad.load('angularFileUpload').then(
                            function() {
                                return uiLoad.load(['js/module/fund/landlordExportImg.js'])
                            });
                    }
                },
                data: {
                    _idstring: _idstring
                },
                scope: $scope,
                width: 1200,
                // height: 700
            }).then(function(data) {
                $scope.tablelandlordManageChanged.fnClearTable();
            }, function(reason) {
                $scope.tablelandlordManageChanged.fnClearTable();
            });
        }
    }



    $scope.coverBgHide = function() {
        $('.operation-none').hide();
        $scope.isCoverBgShow = false;
        // $scope.$apply();
    }



    $scope.$on('createTime.start', function(event, data) {
        $scope.queryParams.dateStart = data ? (data) : "";
        // console.log(data);
    });
    $scope.$on('createTime.end', function(event, data) {
        $scope.queryParams.dateEnd = data ? (data) : "";
        // console.log(data);
    });
    $scope.$on('updateTime.start', function(event, data) {
        $scope.queryParams.applyDateStart = data ? (data) : "";
        // console.log(data);
    });
    $scope.$on('updateTime.end', function(event, data) {
        $scope.queryParams.applyDateEnd = data ? (data) : "";
        // console.log(data);
    });


    // $scope.$on('createTime.start', function(event, data) {
    //     $scope.queryParams.applyDateStart = data ? (data) : "";
    //     // console.log(data);
    // });
    // $scope.$on('createTime.end', function(event, data) {
    //     $scope.queryParams.applyDateEnd = data ? (data) : "";
    //     // console.log(data);
    // });
    // $scope.$on('updateTime.start', function(event, data) {
    //     $scope.queryParams.dateStart = data ? (data) : "";
    //     // console.log(data);
    // });
    // $scope.$on('updateTime.end', function(event, data) {
    //     $scope.queryParams.dateEnd = data ? (data) : "";
    //     // console.log(data);
    // });

});

app.controller('ContractTimeCtrl', function($scope) {
    $scope.today = function() {
        $scope.applyDateStart = "";
        $scope.applyDateEnd = "";
        $scope.dateStart = "";
        $scope.dateEnd = "";
    };

    $scope.closeAll = function() {
        $scope.openContractBeginDated =
            $scope.openContractEndDated = false;
    }

    $scope.openContractBeginDate = function($event) {
        $event.preventDefault();
        $event.stopPropagation();
        $scope.closeAll();
        $scope.openContractBeginDated = true;
    };
    $scope.openContractEndDate = function($event) {
        $event.preventDefault();
        $event.stopPropagation();
        $scope.closeAll();
        $scope.openContractEndDated = true;
    };

    $scope.dateOptions = {
        format: 'yyyy/MM/dd',
        startingDay: 1,
        class: 'datepicker'
    };

    $scope.format = 'yyyy/MM/dd';

    $scope.today();

      $scope.$watch('dateStart', function(newValue, oldValue) {
        if ("[object Date]" === Object.prototype.toString.call(newValue)) {
            $scope.$emit('createTime.start', new Date(moment(newValue)))
        } else if (null === newValue) {
            $scope.$emit('createTime.start', '')
        }
    });
    $scope.$watch('dateEnd', function(newValue, oldValue) {
        if ("[object Date]" === Object.prototype.toString.call(newValue)) {
            $scope.$emit('createTime.end', new Date(moment(newValue)))
        } else if (null === newValue) {
            $scope.$emit('createTime.end', '')
        }
    });
    $scope.$watch('applyDateStart', function(newValue, oldValue) {
        if ("[object Date]" === Object.prototype.toString.call(newValue)) {
            $scope.$emit('updateTime.start', new Date(moment(newValue)))
        } else if (null === newValue) {
            $scope.$emit('updateTime.start', '')
        }
    });
    $scope.$watch('applyDateEnd', function(newValue, oldValue) {
        if ("[object Date]" === Object.prototype.toString.call(newValue)) {
            $scope.$emit('updateTime.end', new Date(moment(newValue)))
        } else if (null === newValue) {
            $scope.$emit('updateTime.end', '')
        }
    });

    // $scope.$watch('applyDateStart', function(newValue, oldValue) {
    //     if ("[object Date]" === Object.prototype.toString.call(newValue)) {
    //         $scope.$emit('createTime.start', new Date(moment(newValue)))
    //     } else if (null === newValue) {
    //         $scope.$emit('createTime.start', '')
    //     }
    // });
    // $scope.$watch('applyDateEnd', function(newValue, oldValue) {
    //     if ("[object Date]" === Object.prototype.toString.call(newValue)) {
    //         $scope.$emit('createTime.end', new Date(moment(newValue)))
    //     } else if (null === newValue) {
    //         $scope.$emit('createTime.end', '')
    //     }
    // });
    // $scope.$watch('dateStart', function(newValue, oldValue) {
    //     if ("[object Date]" === Object.prototype.toString.call(newValue)) {
    //         $scope.$emit('updateTime.start', new Date(moment(newValue)))
    //     } else if (null === newValue) {
    //         $scope.$emit('updateTime.start', '')
    //     }
    // });
    // $scope.$watch('dateEnd', function(newValue, oldValue) {
    //     if ("[object Date]" === Object.prototype.toString.call(newValue)) {
    //         $scope.$emit('updateTime.end', new Date(moment(newValue)))
    //     } else if (null === newValue) {
    //         $scope.$emit('updateTime.end', '')
    //     }
    // });
});